# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# File       : models.py
# Time       ：2022/11/19 21:14
# Author     ：hhs
# version    ：python 3.6
# Description：基础模型类
"""
import uuid

from django.db import models


class BaseModel(models.Model):
    # id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    # auto_now_add: 只有第一次创建时自动更新
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    # auto_now: 每次更新都会会更新该时间
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
    is_deleted = models.BooleanField(default=False, verbose_name="逻辑删除", help_text="逻辑删除")

    class Meta:
        # 表示是基类， 后面模型迁移不会将其同步到数据库
        abstract = True

    def delete(self, using=None, keep_parents=False):
        """重写数据库删除方法实现逻辑删除"""
        self.is_deleted = True
        self.save()
